using System;
using System.Collections.Generic;
using System.Text;

namespace TagTool.Devices.Joystick
{
    public class JoystickManager : IDeviceManager
    {
        private IList<JoystickDevice> deviceList;

        public JoystickManager()
        {
            int numDevs = (int)WinJoystick.GetNumDevs();
            deviceList = new List<JoystickDevice>(numDevs);
            for(int i = 0; i < numDevs; i++)
            {
                deviceList.Add(new JoystickDevice((uint)i));
            }
        }

        #region IDeviceManager Member

        public int NumberOfDevices
        {
            get { return (int)WinJoystick.GetNumDevs(); }
        }

        public IDevice GetDevice(string name)
        {
            foreach (JoystickDevice device in deviceList)
            {
                if (device.Name.Equals(name))
                {
                    return device;
                }
            }
            return null;
        }

        public IDevice GetDevice(int index)
        {
            if ((index < 0) || (index >= deviceList.Count))
            {
                return null;
            }
            return deviceList[index];
        }

        #endregion
    }
}
